/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * ResearchArmItem.java
 * business
 * 2013-5-31上午11:04:19
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.entity;

import java.io.Serializable;
import java.util.Map;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.MapKeyJoinColumn;
import javax.persistence.OneToMany;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;

import com.google.common.collect.Maps;

@Entity
public class ResearchArmItem implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 355322087902355307L;
	
	private String id;	
	
	private String code;
    private String name;
	
	private String remark;	
	
	private ProductType itemType = ProductType.常规产品;
	
	private Map<String,DataItem> dataItems = Maps.newHashMap();
	
		
	public ResearchArmItem() {
		super();
		// TODO Auto-generated constructor stub
	}
	public ResearchArmItem(String code,String name){
	   this.setCode(code);
	   this.setName(name);
	   this.setItemType(ProductType.科研产品);
	   
	}
	
	public String getCode() {
		return code;
	}
	public String getName() {
		return name;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public void setName(String name) {
		this.name = name;
	}

	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	public String getId() {
		return id;
	}
	public String getRemark() {
		return remark;
	}
	public ProductType getItemType() {
		return itemType;
	}
	
	@OneToMany(orphanRemoval=true)
    @Cascade(value = {
    		org.hibernate.annotations.CascadeType.ALL   		
    })
	@JoinTable(name="research_item_dataitem",
                  joinColumns=@JoinColumn(name="item_id"),
                  inverseJoinColumns=@JoinColumn(name="dataitem_id"))
    @MapKeyJoinColumn(name="datalabel",referencedColumnName="label")
	@JSON(serialize=false)
	public Map<String, DataItem> getDataItems() {
		return dataItems;
	}
	public void setId(String id) {
		this.id = id;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public void setItemType(ProductType itemType) {
		this.itemType = itemType;
	}
	public void setDataItems(Map<String, DataItem> dataItems) {
		this.dataItems = dataItems;
	}	
	
}
